package cn.itsource.ymcc.feign;

import cn.itsource.result.JSONResult;
import feign.hystrix.FallbackFactory;
import org.springframework.cloud.openfeign.FeignClient;
import org.springframework.stereotype.Component;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;

@FeignClient(value = "service-course",fallbackFactory = CourseUserLearnClientFallbackFactory.class,contextId = "CommonFeignApi2")
public interface CourseUserLearnClient {

    @RequestMapping(value="/courseUserLearn/{loginId}/{courseId}",method= RequestMethod.GET)
    JSONResult checkUserLearn(@PathVariable("loginId")Long loginId, @PathVariable("courseId")Long courseId);
}

@Component
class CourseUserLearnClientFallbackFactory implements FallbackFactory<CourseUserLearnClient> {
    @Override
    public CourseUserLearnClient create(Throwable throwable) {
        return new CourseUserLearnClient() {

            @Override
            public JSONResult checkUserLearn(Long loginId, Long courseId) {
                throwable.printStackTrace();
                return JSONResult.error("课程服务不可达！！");
            }
        };
    }
}